import java.io.*;
import java.util.*;
public class SearchIR {

	public static void main(String[] args) {
		
		ArrayList<WordTile> arr = new ArrayList<WordTile>();
		//load index file once
		WordListManager.loadIndexFile(new File(args[1]));
		
		//word can be searched multiple times in one thread
		Integer freq = new Integer(0);
		arr = WordListManager.getWordTiles("good");
		System.out.println("frequency: "+ WordListManager.getFrequency());
		WordListManager.writeIndexFile();
		
		
		//test program to locate the query word in collection file
				try{
			
					RandomAccessFile br = new RandomAccessFile(new File(args[1]),"r"); 
				for(WordTile wt : arr){
					
					br.seek(wt.getparaLoc());
					//br.readLine();
					System.out.println(br.readLine());
					System.out.println(":next:");
				}
				System.out.println("count"+"= "+arr.size());
				br.close();
				}
				catch(Exception e){
					e.printStackTrace();
				}
		
		
		
		
		
		
		
		
		
		
		/*      *******************************old code************************************************
		
		
		
		//test program to check working of getWordTiles method in WordListManager
		WordListManager wlm = new WordListManager();
		ArrayList<WordTile> arr = new ArrayList<WordTile>();
		arr = wlm.getWordTiles("god", new File("C:\\Users\\Arun\\workspace\\learning-java\\All Files\\proj2\\genesis\\genesis.txt"));
		for(WordTile wt : arr){
			wt.display();
		}
		//end
		
		//test program to locate the query word in collection file
		try{
	//	BufferedReader br = new BufferedReader(new FileReader(new File("C:\\Users\\Arun\\workspace\\learning-java\\All Files\\proj2\\genesis\\genesis.txt")));
			RandomAccessFile br = new RandomAccessFile(new File("C:\\Users\\Arun\\workspace\\learning-java\\All Files\\proj2\\genesis\\genesis.txt"),"r"); 
		for(WordTile wt : arr){
			
			br.seek(wt.getparaLoc());
			br.readLine();
			System.out.println(br.readLine());
			System.out.println(":next:");
		}
		System.out.println("count"+"= "+arr.size());
		br.close();
		}
		catch(Exception e){
			e.printStackTrace();
		}
					*/
	}

}
